<template>
	<view class="netCard-container">
		<view class="text">
			{{$t('netCard.name23')}}{{$t('netCard.name24')+$t("netCard.name25")}}
		</view>
		<view class="select-title">
			{{$t('netCard.name26')}}：
		</view>
		<view class="netCardList">
			<view :class="{item,itmeActive:item.isManager?true:false}" v-for="(item,index) in netCardList" :key="index"
				@tap="handleTap(item,index)">
				<view class="">{{$t('netCard.name25')}}：{{item.name}}</view>
				<view class="separate"></view>
				<view class="">{{$t('netCard.name27')}}：{{item.speed}}M</view>
				<view class="separate"></view>
				<view class="">IP：{{item.ip}}</view>
			</view>
		</view>
		<view class="bottom">
			<u-button type="warning" :disabled="isDisabled" customStyle="height:100rpx" color="#1D93FF" :text="$t('netCard.name28')"
				@click="handleNext"></u-button>
		</view>
		<u-modal :show="show" :title="$t('netCard.name29')" :content='content'
			@confirm="$fun.jump(`/pageC/equipment2?ids=${ids}`,2)"></u-modal>
		<noneDate v-if="isShow"></noneDate>
	</view>
</template>

<script>
	import noneDate from '@/components/noneDate/noneDate.vue'
	export default {
		components: {
			noneDate
		},
		data() {
			return {
				active: null,
				ids: null,
				netCardList: [],
				show: false,
				content: this.$t('netCard.name30'),
				type: ''

			};
		},
		onLoad(options) {
			this.ids = options.ids
			this.type = options.type
			this.getNetcard()
		},
		computed: {
			isDisabled() {
				return !this.netCardList.some(item => item.isManager)
			},
			isShow() {
				return !this.netCardList.some(item => item.isValid)
			}
		},
		methods: {
			// 获取去网卡信息
			async getNetcard() {
				uni.showLoading({
					title: '',
					mask: true
				})
				const res = await this.$fun.ajax.post('bind/getNetcard', {
					ids: this.ids
				})
				uni.hideLoading()

				this.netCardList = res.data.filter(item => item.isValid)
				if (res.data.length) {
					this.show = false
				} else {
					this.show = true
				}
			},
			// 设置管理网卡
			async managerNetcard() {
				const params = this.netCardList.find(item => item.isManager)
				const res = await this.$fun.ajax.post('bind/managerNetcard', {
					ids: this.ids,
					name: params.name
				})
			},
			handleTap(item, index) {
				this.netCardList.forEach((val, ind) => {
					if (ind === index) {
						val.isManager = true
					} else {
						val.isManager = false
					}
				})
			},
			handleNext() {
				if (this.netCardList.length < 2) return this.$fun.msg(this.$t('netCard.name31'))
				this.managerNetcard()
				if (this.type === this.$t('netCard.name32')) {
					this.$fun.jump('/pageC/dialResult1/dialResult1?ids=' + this.ids)
				} else {
					this.$fun.jump('/pageC/dialResult2/dialResult2?ids=' + this.ids)
				}
			}
		},
	}
</script>

<style lang="scss">
	page {
		background-color: #f5f5f5;
	}

	.netCard-container {
		padding: 30rpx;

		.text {
			color: #7d7d7d;
		}

		.select-title {
			font-size: 34rpx;
			font-weight: 600;
		}

		.netCardList {
			.item {
				display: flex;
				margin: 20rpx 0;
				background-color: #fff;
				padding: 30rpx;
				border-radius: 20rpx;
				font-size: 26rpx;

				.separate {
					width: 1rpx;
					background-color: #5d5d5d;
					margin: 0 10rpx;
				}
			}

			.itmeActive {
				background-color: #1D93FF;
				color: #fff;
			}
		}

		.bottom {
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			height: 200rpx;
			background-color: #fff;
			padding: 50rpx 30rpx;
		}

	}
</style>